package inseniarlingua.lang.ia;

import java.util.HashMap;
import java.util.Map;

import inseniarlingua.lang.VerbDef;

public class VerbIA extends VerbDef 
{
	private static Map<String, String> imperativeMap;
	private static Map<String, String> presentMap;
	private String stem2, stem1;
	private Type type;
	
	private static enum Type { AR, ER, IR }
	
	{
		presentMap = new HashMap<String, String>();
		presentMap.put("esser", "es");
		presentMap.put("haber", "ha");
		presentMap.put("vader", "va");
		
		imperativeMap = new HashMap<String, String>();
		imperativeMap.put("esser", "sia!");
	}
	
	public VerbIA() {
		super();
	}
	
	@Override
	public void setInfinitive(String inf) {
		super.setInfinitive(inf);
		setStem();
	}

	@Override
	public String getPast() {
		//String suffix = (type == Type.AR) ? "ava" : "eva";
		String ret = stem1 + "va";
		return ret;
	}
	
	private void setStem() {
		String inf = getInfinitive();
		stem1 = inf.substring(0, inf.length()-1);
		stem2 = inf.substring(0, inf.length()-2);
		String stype = inf.substring(inf.length()-2).toUpperCase();
		type = Type.valueOf(stype);
	}
	

	@Override
	public String getPresent() {
		String ret = presentMap.get(getValue());
		if (ret == null) {
			ret = stem1;
		}
		return ret;
	}

	@Override
	public String getPresentParticiple() {
		String ret;
		if (type == Type.IR) {
			ret = stem1 + "ente";
		}
		else {
			ret = stem1 + "nte";
		}
		return ret;
	}
	
	@Override
	public String getPastParticiple() {
		String suffix = (type == Type.AR) ? "ate" : "ite";
		String ret = stem2 + suffix;
		return ret;
	}

	@Override
	public String getFuture() {
		String ret = stem1 + "ra";
		return ret;
	}

	@Override
	public String getPerfect() {
		String ret = "ha " + getPastParticiple();
		//String ret = "ha " + stem2 + "ite";
		return ret;
	}

	@Override
	public String getPluperfect() {
		String ret = "habeva " + getPastParticiple();
		//String ret = "habeva " + stem2 + "ite";
		return ret;
	}

	@Override
	public String getFuturePerfect() {
		String ret = "habera " + getPastParticiple();
		//String ret = "habera " + stem2 + "ite";
		return ret;
	}

	@Override
	public String getConditional() {
		String ret = stem1 + "rea";
		return ret;
	}

	@Override
	public String getImperative() {
		String ret = imperativeMap.get(getValue());
		if (ret == null) {
			ret = getPresent() + "!";
		}
		return ret;
	}
}
